<template>
	<view class="flex-col page  ">
		<view class="flex-col section_2">
			<view class="px-3">
				<template v-if="list.length">
					<div class="coupons mt-12" v-for="(v,i) in list" :key="i">
						<div class="coupon ">
							<!-- bac-jian 未领取样式 -->
							<div class="coupon-intro   d-flex align-items-center "
								:class="!v.is_owned?'bac-jian':'bg-AAB5BF'">
								<view class="d-flex text-white  align-items-center flex-column" v-if="v.min_price==0">
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">立减券</view>
								</view>
								<view class="d-flex text-white  align-items-center flex-column" v-else>
									<view class="d-flex align-items-baseline">
										<view class="font-36 text-white font-600">{{v.reduce_price}}</view>
										<view class="ps-1">元</view>
									</view>
									<view class="">满减券</view>
							<!-- 		<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">满</view>
										<view class="font-36 text-white font-600 ps-2">{{v.min_price}}</view>
									</view>
									<view class="d-flex align-items-baseline justify-content-between w-100">
										<view class="ps-1">减</view>
										<view class="font-36 text-white font-600 ps-2">{{v.reduce_price}}</view>
									</view> -->
								</view>

							</div>
							<div class="coupon-value ">
								<view class="d-flex w-100 justify-content-between ">
									<view class="ps-3 p-3 flex-1">
										<view class="font-20 text-222426 pb-3 ">{{v.coupon_name}}</view>
										<view class="text-AAB5BF font-14 pb-1">有效期：</view>
										<view class="text-222426 font-14" v-if="2 == v.expire_type">
											<text>{{v.start_time |setTime}}</text>-<text>{{v.end_time|setTime}}</text>
										</view>
										<view class="text-222426 font-14" v-else>
											<text>领取后{{v.expire_day}}天有效</text>
										</view>
									</view>
									<view v-if="v.is_owned" class="font-14 status text-AAB5BF font-500"
										style="padding: 0 28rpx;">已领取</view>
									<view v-else @click="receive(v.id,i)" class="font-14 status text-theme font-500"
										style="padding: 0 28rpx;">立即领取</view>
								</view>
							</div>
						</div>
					</div>
				</template>
				<view v-else class="empty d-flex justify-content-center flex-column align-items-center h-100">
					<image src="../../static/imgs/empty.png" class="img" />
					<view class="text-AAB5BF mt-1 pt-3">暂时没有数据</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import moment from 'moment'
	// import {
	// 	topUpDetail,
	// 	useDetail
	// } from '../../common/commonData.js';
	export default {
		data() {
			return {
				list: [],
			};
		},

		onLoad() {
			uni.hideShareMenu()
			if (!this.vuex_has_login) {
				this.$u.toast('请先登录');
				return
			} else {}
			this.getCouponList()
		},
		methods: {
			getCouponList() {
				this.$u.api.getCouponList().then((res) => {
					this.list = res.data
				})

			},
			getInfo() {
				if (this.vuex_has_login) {
					this.$u.api.getUserInfo().then(res => {
						this.$u.vuex('vuex_user', {
							...this.vuex_user,
							...res.data
						})
					})
				}
			},
			receive(id, i) {
				this.$u.api.submitTakecoupon({
					couponid: id
				}).then((res) => {
					this.$u.toast(res.msg)
					if (1 == res.code) {
						// this.getCouponList()
						this.list[i].is_owned = 1
						this.getInfo()
					}
				})
			}

		},
	};
</script>

<style scoped lang="scss">
	.page {
		$background-color: #eee;
		$radius-size: 8px;

		.coupons {
			width: 100%;

			.coupon {
				margin-bottom: 20px;
				display: flex;

				>div {
					padding: 10px 20px;
					border-radius: $radius-size;
				}

				.bac-jian {
					background: linear-gradient(326.28deg, #D85886 1.25%, #F692B6 100%);
				}

				.coupon-intro {
					position: relative;
					padding: 0;
					width: 194rpx;
					justify-content: center;

					ul {
						color: #aaa;
						padding-left: 20px;
					}

					&:after {
						content: ' ';
						border: 2px dashed white;
						height: 100%;
						position: absolute;
						top: 0;
						right: -2px;
						z-index: 2;
					}
				}

				.coupon-value {
					padding: 0;
					display: flex;
					flex: 1;
					position: relative;
					background: #F2F9FC;
					color: #fff;
					font-size: 38px;
					align-items: center;

					&:before {
						content: ' ';
						width: $radius-size * 2;
						height: $radius-size * 2;
						position: absolute;
						top: -$radius-size;
						left: -$radius-size;
						border-radius: 100%;
						background: white;
					}

					&:after {
						content: ' ';
						width: $radius-size * 2;
						height: $radius-size * 2;
						position: absolute;
						bottom: -$radius-size;
						left: -$radius-size;
						border-radius: 100%;
						background: white;
					}

					.status {
						writing-mode: vertical-lr;
						text-align: center;
						border-left: 2px dashed #DAE4EE;

					}
				}
			}
		}

	}

	.empty {
		padding-top: calc(30vh - 244rpx);

		image {
			width: 288rpx;
			height: 304rpx;
		}
	}
</style>